# @Time    : 2021/1/19 14:23
# @Author  : LDY
# @Email   : 274884591@qq.com
# @File    : orderTreasure.py
# @desc    : 订货宝业务代码
# @Software: PyCharm
import time

from Business.GUI.Objects.Ordertreasure.orderPom import OrderPom
from TestData.GUI.Ordertreasure.DataDict import Data
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains


class OrderTreasure:
    def __init__(self):
        self.pom = OrderPom()
        # 获取driver
        self.driver = self.pom.dr

    def login(self):
        self.pom.get_username_ele().send_keys("shanghai")
        self.pom.get_password_ele().send_keys("dhb168")
        self.pom.get_loginbutton_ele().click()
        desc = self.pom.get_company_ele().text
        return desc
    # 余托弟
    def order_(self):
        '''点击订单'''
        self.pom.get_order_ele().click()
        self.pom.get_fixed_ele()
        desc = self.pom.get_fixed_ele().text
        return desc

    def indent(self):
        '''点击订货单'''
        self.pom.get_indent_ele().click()
        desc = self.pom.get_indenttext_ele().text
        return desc


    #查询
    def indent_query(self,search=None,orderdata=time.time(),enddata=None,orderZT=None,SKZT=None):
        #定位搜索框输入内容
        self.pom.get_search_ele().send_keys(search)
        #定位订单状态并点击
        self.pom.get_orderZT__ele().click()
        #定位订单状态下拉框并点击
        time.sleep(2)
        self.pom.get_ordercheckBox__ele().click()
        #点击查询
        self.pom.get_query_ele().click()
        #点击查询后文本信息
        time.sleep(2)
        actual_str = self.pom.get_IDsearchtext_ele().text
        str_ = actual_str.strip(' ')
        actual_li = str_.split('\n')
        actual_list=[]
        actual_list.append(actual_li[1])
        #点击重置
        time.sleep(1)
        self.pom.get_reset_ele().click()
        #点击查询
        self.pom.get_query_ele().click()
        return actual_list

    # 点击重置
    def indent_Resset(self):
        self.pom.get_reset_ele().click()
        desc = self.pom.get_search_ele().text
        return desc

    # 点击新增
    def indent_Add(self):
        time.sleep(2)
        self.pom.get_add__ele().click()
        # 切换至嵌套页面
        self.pom.get_addiframe__ele()
        # 获取返回文本信息
        desc = self.pom.get_addorder__ele().text
        # 点击关闭当前页面
        self.pom.dr.back()
        return desc

    # 订货单切换至首页
    def indent_homePage(self):
        self.pom.get_indentHomepage_ele().click()
        time.sleep(2)
        desc = self.pom.get_company_ele().text
        self.pom.dr.refresh()
        return desc

    # 点击展开
    def indent_Unfold(self):
        self.pom.get_indentUnfold__ele().click()
        desc = self.pom.get_unfoldHide__ele().text
        return desc

    # 点击查看
    def indent_Check(self):
        self.pom.get_indentCheck__ele().click()
        # 切换至嵌套页面
        self.pom.get_orderiframe__ele()
        # 获取订单详情内容文本
        desc_ = self.pom.get_orderDetail__ele().text
        time.sleep(1)
        self.pom.dr.back()
        self.pom.dr.refresh()
        return desc_

    # 点击客户名称
    def indent_cusName(self):
        self.pom.get_cusName__ele().click()
        self.pom.get_cusiframe__ele()
        time.sleep(2)
        desc_str = self.pom.get_cusDetailCon__ele().text
        desc_list = desc_str.split('\n')
        self.pom.dr.back()
        self.pom.dr.refresh()
        return desc_list

    # 王可庆
    def kehuliebiao(self):
        time.sleep(2)
        self.Action = ActionChains(self.driver)
        self.Action.move_to_element(self.pom.get_keuhu_ele()).perform()
        time.sleep(2)
        self.Action.move_to_element(self.pom.get_kehuliebiao()).click().perform()
        actual = self.pom.get_kehuliebiao_text().text
        return actual

    def wenhao(self):
        actual = []
        self.Action = ActionChains(self.driver)
        self.Action.move_to_element(self.pom.get_wenhao()).perform()
        time.sleep(2)
        actual1 = self.pom.get_wenhaotext().text
        actual2 = actual1.split('\n')
        actual.append(actual2[0])
        self.pom.get_bangzhu().click()
        time.sleep(2)
        biaoqian = self.driver.window_handles
        self.driver.switch_to.window(biaoqian[1])
        actual3 = self.pom.get_shurukuang().get_attribute('placeholder')
        actual.append(actual3)
        self.driver.close()
        self.driver.switch_to.window(biaoqian[0])
        return actual

    def shouye(self):
        self.pom.get_shouye().click()
        time.sleep(2)
        actual = self.pom.get_shouyetext().text
        self.driver.back()
        return actual

    def xinzeng(self):
        time.sleep(2)
        self.pom.get_xinzeng().click()
        time.sleep(2)
        self.driver.switch_to.frame(self.pom.get_qiehuan())
        time.sleep(2)
        actual = self.pom.get_xinzengtext().text
        self.driver.back()
        self.pom.get_closexinzeng().click()
        return actual

    def sanshenluehao(self, ready=1):
        list1 = []
        list2 = []
        self.Action = ActionChains(self.driver)
        time.sleep(1)
        self.Action.move_to_element(self.pom.get_shengluehao()).perform()
        time.sleep(1)
        list1.append(self.pom.get_shengluehaotext().text)
        time.sleep(1)
        if ready != 0:
            self.pom.get_shengluehaofenlei().click()
            self.driver.switch_to.frame(self.pom.get_qiehuan())
            time.sleep(2)
            list1.append(self.pom.get_sanshengluexinzeng().text)
            self.driver.back()
            self.pom.get_closeyemian().click()
            for i in list1:
                if '\n' in i:
                    a = i.replace('\n', ',')
                    list2.append(a)
                else:
                    list2.append(i)
            return list2
        self.pom.get_shengluehaopiliang().click()
        self.driver.switch_to.frame(self.pom.get_qiehuan())
        time.sleep(2)
        uuuu = self.pom.get_piliangguanlitext().text
        self.driver.back()
        time.sleep(2)
        self.pom.get_closeyemian().click()
        return uuuu

    def zhankai(self):
        self.pom.get_zhankai().click()
        kk = self.pom.get_yincang().text
        time.sleep(2)
        self.pom.get_dinghuotubiao().click()
        self.driver.refresh()
        return kk

    # 王清玉

    # 点击库存按钮
    def click_StockAndFixed_Button(self):
        time.sleep(2)
        self.pom.get_stockbutton_ele().click()
        time.sleep(2)
        self.pom.get_FixedButton_ele().click()

    def mouse(self):
        action = ActionChains(self.driver)
        return action

    # 切换进嵌套页面
    def SwitchToIframe(self):
        # driver = OpenBrowser.get_driver(Dir.OrderUrl)
        driver = self.driver
        iframe = self.pom.iframes()
        driver.switch_to.frame(iframe)

    # 跳转到供应商管理界面
    def jumpToSqe(self):
        # self.pom.get_stockbutton_ele().click()
        # 点击库存
        self.click_StockAndFixed_Button()
        # 点击供应商管理按钮
        self.pom.get_SQEButton_ele().click()
        # 切换到嵌套列表里
        self.SwitchToIframe()
        # 获取页面"供应供应商管理"文本信息
        desc = self.pom.get_SQEText_ele().text
        # 切出嵌套页面
        self.driver.switch_to.default_content()
        # 关闭页面刷新浏览器
        self.pom.get_close_ele().click()
        time.sleep(2)
        self.driver.refresh()
        return desc

    # 供应商-搜索框
    def sqeSearch(self):
        # 点击库存
        self.click_StockAndFixed_Button()
        # 点击供应商管理按钮
        self.pom.get_SQEButton_ele().click()
        # 切换到嵌套列表里
        self.SwitchToIframe()
        time.sleep(2)
        # 在搜索框中输入文本
        self.pom.get_Search_ele().send_keys('测试1')
        # 点击搜索框
        self.pom.get_SearchButton_ele().click()
        time.sleep(2)
        # 获取页面显示的查询结果文本信息
        desc = self.pom.get_SearchResult_ele().text
        # 切出嵌套页面
        self.driver.switch_to.default_content()
        # 刷新浏览器
        self.pom.get_close_ele().click()
        time.sleep(2)
        self.driver.refresh()
        return desc

    # 供应商-新增供应商全部信息
    def addSqe(self, AddMethod=None):
        """
        :param AddMethod: 添加方式(0代表填入全部信息,1代表只填入供应商名字)
        :return:
        """
        SQEimages = ['测试2', '1', '世纪大道', '无', '张三', '13122233344', '111222', '111222@qq.com', '李四', '世界银行',
                     '622334455', '无', '2333']
        if AddMethod == 0:
            # 点击库存
            self.click_StockAndFixed_Button()
            # 点击供应商管理按钮
            self.pom.get_SQEButton_ele().click()
            # 切换到嵌套列表里
            self.SwitchToIframe()
            # 点击添加供应商按钮
            self.pom.get_AddSQEButton_ele().click()  #
            # 输入供应商名字
            self.pom.get_AddSQEName_ele().send_keys(SQEimages[0])
            # 输入供应商编号
            self.pom.get_AddSQENumber_ele().send_keys(SQEimages[1])
            # 点击地址框
            self.pom.get_AddSQEAddress_ele().click()
            # 选择省份
            self.pom.get_SelProvince_ele().click()
            # 选择城市
            self.pom.get_SelCity_ele().click()
            # 选择县区
            self.pom.get_SelCount_ele().click()
            # 输入详细地址
            self.pom.get_AddSQEDetailAddress_ele().send_keys(SQEimages[2])
            # 输入备注
            self.pom.get_AddSQERemarks_ele().send_keys(SQEimages[3])
            # 输入联系人姓名
            self.pom.get_AddSQELinkName_ele().send_keys(SQEimages[4])
            # 输入手机号
            self.pom.get_AddSQELinkPhone_ele().send_keys(SQEimages[5])
            # 输入座机号
            self.pom.get_AddSQELinkPlane_ele().send_keys(SQEimages[6])
            # 输入邮箱
            self.pom.get_AddSQELinkEmail_ele().send_keys(SQEimages[7])  #
            # 键盘事件,将页面下滑
            self.pom.get_AddSQELinkEmail_ele().send_keys(Keys.PAGE_DOWN)  #
            time.sleep(2)
            # 输入开户名称
            self.pom.get_AddSQEOpenName_ele().send_keys(SQEimages[8])
            # 输入开户银行
            self.pom.get_AddSQEOpenBank_ele().send_keys(SQEimages[9])
            # 银行账号
            self.pom.get_AddSQEBankAcc_ele().send_keys(SQEimages[10])
            # 开票抬头
            self.pom.get_AddSQEInvoiceTitle_ele().send_keys(SQEimages[11])
            # 纳税人识别号
            self.pom.get_AddSQETaxpayerNum_ele().send_keys(SQEimages[12])
            # 点击确认按钮
            self.pom.get_ConButton_ele().click()  #
            # 获取值做断言
            time.sleep(2)
            desc = self.pom.get_assertaddSqe_ele().text
            time.sleep(1)
            self.driver.find_element_by_xpath(
                '//*[@id="Supplier-index-list-fresh-box"]/table/tbody/tr[1]/td[8]/div/div/a[2]').click()
            time.sleep(2)
            e1 = self.driver.find_element_by_xpath('/html/body/div[8]/div/div/div[3]/button[1]').click()
            self.pom.action_click(e1)
            # 切换出嵌套页面
            self.driver.switch_to.default_content()
            time.sleep(2)
            # 刷新浏览器
            self.pom.get_close_ele().click()
            time.sleep(2)
            self.driver.refresh()
            return desc
        if AddMethod == 1:
            # 点击库存
            self.click_StockAndFixed_Button()
            # 点击供应商管理按钮
            self.pom.get_SQEButton_ele().click()
            # 切换到嵌套列表里
            self.SwitchToIframe()
            # 点击新增供应商按钮
            self.pom.get_AddSQEButton_ele().click()
            # 输入供应商名字
            self.pom.get_AddSQEName_ele().send_keys(SQEimages[0])
            # 键盘事件,将页面下滑
            self.pom.get_AddSQELinkEmail_ele().send_keys(Keys.PAGE_DOWN)
            time.sleep(2)
            # 点击确认按钮
            self.pom.get_ConButton_ele().click()
            time.sleep(2)
            # 获取值做断言
            desc = self.pom.get_assertaddSqe_ele().text
            time.sleep(1)
            self.driver.find_element_by_xpath('//*[@id="Supplier-index-list-fresh-box"]/table/tbody/tr[1]/td[8]/div/div/a[2]').click()
            time.sleep(2)
            e1 = self.driver.find_element_by_xpath('/html/body/div[8]/div/div/div[3]/button[1]').click()
            self.pom.action_click(e1)
            # 切换出嵌套页面
            self.driver.switch_to.default_content()
            time.sleep(2)
            # 刷新浏览器
            self.pom.get_close_ele().click()
            time.sleep(2)
            self.driver.refresh()
            return desc

    # 采购单-查询
    def orderSearch(self):
        # 点击库存按钮
        self.click_StockAndFixed_Button()
        # 点击采购单按钮
        self.pom.get_OrderButton_ele().click()
        time.sleep(2)
        # 输入采购单编号
        self.pom.get_OrderId_ele().send_keys('JH')
        # 输入采购单起始时间
        self.pom.get_OrderStartDate_ele().send_keys('2021-01-01')
        # 点击订单状态下拉框
        self.pom.get_OrderStatus_ele().click()
        # 点击下拉框中的值
        self.pom.get_OrderStatusValue_ele().click()
        # 点击搜索按钮
        self.pom.get_OrderSearchButton_ele().click()
        # 断言
        desc = self.pom.get_assertSearchOrder_ele().text
        # 刷新浏览器
        self.pom.get_close_ele().click()
        time.sleep(2)
        self.driver.refresh()
        return desc

    # 采购单-新增采购单
    def addOrder(self):
        # 点击库存按钮
        self.click_StockAndFixed_Button()
        # 点击采购单按钮
        self.pom.get_OrderButton_ele().click()
        # 点击新增采购单按钮
        self.pom.get_AddOrder_ele().click()
        # 点击供应商下拉框
        self.pom.get_SelectSQE_ele().click()
        # 选择供应商
        self.pom.get_SelectSQEValue_ele().click()
        # 点击仓库下拉框
        self.pom.get_SelectHouse_ele().click()
        # 选择仓库
        self.pom.get_SelectHouseValue_ele().click()
        # 点击选择交货日期框输入日期
        time.sleep(2)
        self.pom.get_SelectDeliveryDate_ele().click()
        time.sleep(2)
        self.pom.get_SelectDeliveryDateSure_ele().click()
        # 点击输入商品名称框输入商品名称(执行前先执行一段js代码使框变为可见)
        time.sleep(2)
        self.driver.execute_script(
            'document.querySelector("#dhb-wrap > div > div.padding-normal > div.ant-table-wrapper > div > div > div > div > div > div.ant-table-body > table > tbody > tr:nth-child(1) > td:nth-child(3) > div > div > div > div > div.ant-select-search.ant-select-search--inline").style.display="block"')
        self.pom.get_SelectGoodsName_ele().send_keys('梦龙')
        # 点击输入商品名称后出现的下拉框的值
        self.pom.get_SelectGoodsNameValue_ele().click()
        # 点击采购数量框,输入数量
        self.pom.get_SelectGoodsNum_ele().send_keys('1')
        # 点击进货价框输入价格
        self.pom.get_SelectGoodsPrice_ele().send_keys('2')
        # 点击订单备注框输入文本
        self.pom.get_GoodsRemark_ele().send_keys('测试')
        # 点击内部沟通框输入文本
        self.pom.get_GoodsComm_ele().send_keys('测试')
        # 点击确定按钮
        self.pom.get_SureButton_ele().click()
        # 断言
        time.sleep(2)
        desc = self.pom.get_assertAddGoods_ele().text
        time.sleep(2)
        # 刷新浏览器
        self.pom.get_close_ele().click()
        time.sleep(2)
        self.driver.refresh()
        return desc

    # 仓库管理-新增仓库
    def addDepot(self):
        # 点击库存按钮和固定按钮
        self.click_StockAndFixed_Button()
        # 点击仓库管理按钮
        time.sleep(2)
        self.pom.get_DepotButton_ele().click()
        # 切换到嵌套页面
        self.SwitchToIframe()
        # 点击新增仓库按钮
        self.pom.get_AddDepotButton_ele().click()
        # 点击仓库名称输入仓库名称
        self.pom.get_DepotName_ele().send_keys('测试1')
        # 点击所在地,弹出下拉框
        self.pom.get_DepotAddress_ele().click()
        # 选择省份
        self.pom.get_DepotAddressProvince_ele().click()
        # 选择城市
        self.pom.get_DepotAddressCity_ele().click()
        # 选择县区
        self.pom.get_DepotAddressCounty_ele().click()
        # 输入详细地址
        self.pom.get_DepotDetailAddress_ele().send_keys('世纪大道')
        # 输入归属地
        self.pom.get_DepotHome_ele().click()
        # 输入联系电话
        self.pom.get_DepotLinkPhone_ele().send_keys('13123333333')
        # 点击确定按钮
        self.pom.get_DepotSubmiteButton_ele().click()
        # 断言
        time.sleep(2)
        desc = self.pom.get_assertAddDepot_ele().text
        time.sleep(2)
        # 切出嵌套页面
        self.driver.switch_to.default_content()
        # 刷新浏览器
        self.pom.get_close_ele().click()
        time.sleep(2)
        self.driver.refresh()
        return desc

    # 仓库管理-修改仓库
    def updateDepotImg(self):
        # 点击库存按钮和固定按钮
        self.click_StockAndFixed_Button()
        # 点击仓库管理按钮
        time.sleep(2)
        self.pom.get_DepotButton_ele().click()
        # 切换到嵌套页面
        self.SwitchToIframe()
        # 执行js代码使修改按钮变得可见  document.querySelector("#Stock-stockManager-list-fresh-box > table > tbody > tr:nth-child(9) > td.list-operate.table-p-r-sm > div").style.display='block'
        time.sleep(2)
        self.driver.execute_script(
            'document.querySelector("#Stock-stockManager-list-fresh-box > table > tbody > tr:nth-child(10) > td.list-operate.table-p-r-sm > div").style.display="block"')
        time.sleep(2)
        # 修改按钮出现,点击修改按钮
        self.pom.get_modDepotButton_ele().click()
        # 修改备注
        self.pom.get_modDepotRemark_ele().clear()
        self.pom.get_modDepotRemark_ele().send_keys('无')
        # 点击提交按钮
        self.pom.get_modDepotSureButton_ele().click()
        # 断言
        time.sleep(2)
        desc = self.pom.get_assertUpdateDepot_ele().text
        time.sleep(2)
        # 切出嵌套页面
        self.driver.switch_to.default_content()
        # 刷新浏览器
        self.pom.get_close_ele().click()
        time.sleep(2)
        self.driver.refresh()
        return desc

    # 仓库管理_删除按钮
    def deleteDeopt(self):
        # 点击库存按钮和固定按钮
        self.click_StockAndFixed_Button()
        # 点击仓库管理按钮
        time.sleep(2)
        self.pom.get_DepotButton_ele().click()
        # 切换到嵌套页面
        self.SwitchToIframe()
        # 执行js使删除键变得可见 document.querySelector("#Stock-stockManager-list-fresh-box > table > tbody > tr:nth-child(9) > td.list-operate.table-p-r-sm > div").style.display='block'
        time.sleep(2)
        self.driver.execute_script(
            'document.querySelector("#Stock-stockManager-list-fresh-box > table > tbody > tr:nth-child(10) > td.list-operate.table-p-r-sm > div").style.display="block"')
        time.sleep(2)
        # 定位删除按钮
        self.pom.get_DeleteDepotButton_ele().click()
        # 断言
        time.sleep(2)
        desc = self.pom.get_assertDeleteDepotAlter_ele().text
        # 点击弹框中的确认
        time.sleep(2)
        self.pom.get_DeleteDepotAlter_ele().click()
        time.sleep(2)
        # 切出嵌套页面
        self.driver.switch_to.default_content()
        # 刷新浏览器
        self.pom.get_close_ele().click()
        time.sleep(2)
        self.driver.refresh()
        return desc

    # 李丁勇
    # 查询商品
    def query_goods(self, search=None, goodtype=None, goodbrand=None, goodstore=None, goodimage=None, reset=False):
        # 点击商品
        self.pom.get_goods_ele().click()
        # 点击商品列表
        self.pom.get_goodslist_ele().click()
        # 移动到查询,以收起左边弹框
        self.pom.move_ele(self.pom.get_good_querybutton_ele())
        time.sleep(1)
        # 通过判断展开按钮是否为展开文本决定是否点击
        if self.pom.get_zhankai_button().text == '展开':
            # 点击展开
            self.pom.get_zhankai_button().click()
        time.sleep(2)
        flag = False
        # 搜索框输入内容
        if search:
            self.pom.get_good_search_ele().send_keys(search)
        # 隐藏div标签从3开始,每点击一次下拉框+1
        div_num = 3
        # 选择商品分类
        if goodtype:
            # 定位商品分类并点击
            self.driver.find_element_by_xpath(
                '//*[@id="dhb-wrap"]/div/div[2]/div[1]/div/div[1]/div[1]/div[2]/span/span/span[1]/span').click()
            # 判断商品分类是否被点击
            flag = True
            # 通过字典获取键值num，获取不到则默认1
            num = Data.good_type.get(goodtype, 1)
            self.pom.get_good_type_ele(num).click()
            div_num += 1
        # 选择商品品牌
        if goodbrand:
            # 定位商品品牌并点击
            self.driver.find_element_by_xpath(
                '//*[@id="dhb-wrap"]/div/div[2]/div[1]/div/div[1]/div[1]/div[3]/div/div/div/div[1]').click()
            # self.pom.action_click(ele)
            # 通过字典获取键值num，获取不到则默认1
            num = Data.good_brand.get(goodbrand, 1)
            if num > 8 and flag:
                js = f"var q=document.getElementsByClassName('ant-select-dropdown-menu  ant-select-dropdown-menu-root ant-select-dropdown-menu-vertical')[{div_num - 4}].scrollTop = 120"
                # 修改滚动条的位置，模拟滚动
                self.driver.execute_script(js)
            elif num > 8 and not flag:
                js = f"var q=document.getElementsByClassName('ant-select-dropdown-menu  ant-select-dropdown-menu-root ant-select-dropdown-menu-vertical')[{div_num - 3}].scrollTop = 120"
                self.driver.execute_script(js)
            time.sleep(1)
            self.driver.find_element_by_xpath(f'/html/body/div[{div_num}]/div/div/div/ul/li[{num}]').click()
            div_num += 1
        # 选择商品仓库
        if goodstore:
            # 定位商品仓库并点击
            self.driver.find_element_by_xpath(
                '//*[@id="dhb-wrap"]/div/div[2]/div[1]/div/div[1]/div[2]/div[1]/div/div/div/div[1]').click()
            # 通过字典获取键值num，获取不到则默认1
            num = Data.good_store.get(goodstore, 1)
            # 定位下拉框中的元素
            ele = self.driver.find_element_by_xpath(f'/html/body/div[{div_num}]/div/div/div/ul/li[{num}]')
            ele.click()
            div_num += 1
        # 选择商品是否有图
        if goodimage:
            # 定位商品是否有图选项
            self.driver.find_element_by_xpath(
                '//*[@id="dhb-wrap"]/div/div[2]/div[1]/div/div[1]/div[2]/div[5]/div/div/div/div[1]').click()
            # 通过字典获取键值num，获取不到则默认1
            num = Data.good_image.get(goodimage, 1)
            # 定位下拉框中的元素
            self.driver.find_element_by_xpath(f'/html/body/div[{div_num}]/div/div/div/ul/li[{num}]').click()
            div_num += 1
        # 是否重置条件
        if reset:
            # 点击重置
            self.driver.find_element_by_xpath('//*[@id="dhb-wrap"]/div/div[2]/div[1]/div/div[2]/button[2]').click()
            time.sleep(2)
        # 点击查询
        self.pom.get_good_querybutton_ele().click()
        time.sleep(2)
        total = self.pom.get_total().text
        first_num = self.pom.get_first_num().text.split('\n')
        if len(first_num) <= 18:
            # 没有商品信息时返回暂无数据
            first_num = first_num[17]
        else:
            # 有商品信息时返回第一条记录的商品编号
            first_num = first_num[18]
        # 关闭当前页面
        self.pom.get_close_ele().click()
        time.sleep(2)
        # 每次执行结束需要刷新一次页面，清空隐藏元素缓存
        self.driver.refresh()
        return total, first_num

    # 商品列表页面修改商品标识
    def modify_goods_logo(self, new=None, recommend=None, hot=None, gift=None, select=None, accept=True, option=True):
        # 点击商品
        self.pom.get_goods_ele().click()
        # 点击商品列表
        self.pom.get_goodslist_ele().click()
        # 移动到查询,以收起左边弹框
        self.pom.move_ele(self.pom.get_good_querybutton_ele())
        time.sleep(2)
        if option:
            # 点击第一条记录的勾选框
            self.pom.get_first_button().click()
        # 点击下方的批量操作
        self.pom.get_mul_option().click()
        # 点击批量操作中的设置商品标识
        self.pom.get_set_logo().click()
        if not option:
            # 不选中则直接返回提示语
            time.sleep(1)
            info = self.pom.option_info().text
            # 关闭当前页面
            self.pom.get_close_ele().click()
            time.sleep(2)
            # 每次执行结束需要刷新一次页面，清空隐藏元素缓存
            self.driver.refresh()
            return info
        # 等待页面加载完成
        time.sleep(2)
        # 点击新品标识，默认不点击
        if new:
            self.pom.set_new_logo().click()
        # 点击推荐标识，默认不点击
        if recommend:
            self.pom.set_recommend_logo().click()
        # 点击热销标识，默认不点击
        if hot:
            self.pom.set_hot_logo().click()
        # 点击赠品标识，默认不点击
        if gift:
            self.pom.set_gift_logo().click()
        # 点击精选标识，默认不点击
        if select:
            self.pom.set_select_logo().click()
        # 默认点击确定
        if accept:
            # 点击确定
            self.pom.set_accept_logo().click()
        else:
            # 点击取消
            self.pom.set_dismiss_logo().click()
        # 获取提示信息
        time.sleep(2)
        optioninfo = self.pom.option_info().text[:4]
        # 获取第一条记录的商品名称内容
        time.sleep(2)
        firstname = self.pom.get_first_name().text
        namelist = firstname.split('\n')
        # 关闭当前页面
        self.pom.get_close_ele().click()
        time.sleep(2)
        # 每次执行结束需要刷新一次页面，清空隐藏元素缓存
        self.driver.refresh()
        return optioninfo, namelist[0]

    # 查看商品图片页面标题
    def goods_image_page(self):
        # 点击商品
        self.pom.get_goods_ele().click()
        # 点击商品图片
        self.pom.get_goodsimage_ele().click()
        # 移动到上方关闭按钮以收起弹框
        self.pom.move_ele(self.pom.get_close_ele())
        time.sleep(1)
        head = self.driver.find_element_by_xpath(
            '//*[@id="app"]/div/div/div[1]/div[2]/div[2]/div/div/span').text
        # 进入嵌套页面
        self.driver.switch_to.frame(1)
        time.sleep(1)
        title = self.pom.get_good_image_page().text
        # 切回到默认页面
        self.driver.switch_to.default_content()
        # 关闭当前页面
        self.pom.get_close_ele().click()
        time.sleep(2)
        # 每次执行结束需要刷新一次页面，清空隐藏元素缓存
        self.driver.refresh()
        return head, title

    # 商品明细页面做上下架操作
    def goods_shelf(self, option=True):
        # 点击商品
        self.pom.get_goods_ele().click()
        # 点击商品明细
        self.pom.get_goodsinfo().click()
        # 点击第一条记录的上下架按钮
        e1 = self.pom.get_off_shelf()
        # 移动到上下架按钮以收起左边弹框
        self.pom.move_ele(e1)
        before = e1.text
        e1.click()
        time.sleep(1)
        # 获取上下架界面提示信息
        information = self.pom.get_off_info().text
        # 默认点击取消
        if option:
            self.pom.action_click(self.pom.get_dismiss_button())
            time.sleep(2)
            after = e1.text
        else:
            self.pom.action_click(self.pom.get_accept_button())
            time.sleep(2)
            after = e1.text
        time.sleep(1)
        # 只获取前四个值，防止获取到执行中类似的提示语
        option_info = self.pom.option_info().text[:4]
        # 关闭当前页面
        self.pom.get_close_ele().click()
        time.sleep(2)
        # 每次执行结束需要刷新一次页面，清空隐藏元素缓存
        self.driver.refresh()
        return before, after, information, option_info

    # 商品经营范围页面，获取编辑界面的提示信息
    def goods_scope(self):
        # 点击商品
        self.pom.get_goods_ele().click()
        # 点击商品经营范围
        self.pom.get_goodsscope().click()
        # 进入嵌套页面
        self.driver.switch_to.frame(1)
        # 移动并点击右边授权归属地区元素，以显现编辑按钮元素
        self.pom.move_ele(self.pom.get_first_scope())
        self.pom.get_first_scope().click()
        time.sleep(2)
        # 出现的编辑按钮，获取文本信息，并点击
        edit_text = self.pom.get_scope_edit().text
        self.pom.get_scope_edit().click()
        # 获取编辑界面的左下角提示信息
        prompt_info = self.pom.get_scope_editpage().get_attribute('innerText')
        time.sleep(2)
        # 点击取消
        self.driver.find_element_by_xpath('//*[@id="fm-goods-add"]/div[2]/button[2]').click()
        # 切回到默认页面
        self.driver.switch_to.default_content()
        # 关闭当前页面
        self.pom.get_close_ele().click()
        time.sleep(2)
        # 每次执行结束需要刷新一次页面，清空隐藏元素缓存
        self.driver.refresh()
        return edit_text, prompt_info


if __name__ == '__main__':
    order = OrderTreasure()
    order.login()
    # print(order.query_goods("", "爆款推荐", "和路雪-梦龙", "虚拟仓", "有图", reset=False))
    # # print(order.query_goods())
    # # print(order.modify_goods_logo('新品', '推荐', '热销', '赠品', '', True, False))
    # # # print(order.query_goods("", "", "维加", "", "", False))
    # print(order.goods_image_page())
    # print(order.goods_shelf(True))
    print(order.addOrder())
    print(order.orderSearch())
